package com.acce.base.utils;

import java.io.File;

import org.apache.log4j.Logger;

public class FileUtils {
	
	private Logger logger = Logger.getLogger(FileUtils.class);
	
	String basePath = PropertiesUtil.getInstance().getProperties("ftl.properties").get("basePath").toString();
	
	String htmlFolder = PropertiesUtil.getInstance().getProperties("ftl.properties").get("htmlFolder").toString();
	
	String inRecordFolder = PropertiesUtil.getInstance().getProperties("ftl.properties").get("inRecordFolder").toString();
	
	private FileUtils() {
		init();
	}
	
	private void init() {
		String folders = null;
		try {
			folders = basePath + File.separator + htmlFolder + File.separator + inRecordFolder;
			File base = new File(folders);
			base.mkdirs();
		} catch(Exception ex) {
			logger.info("nsy-wape::folders needed to be created: " + folders);
		}
	}
	
	public static FileUtils getInstance() {
		return Holder.instance;
	}
	
	private static class Holder {
	    public static final FileUtils instance = new FileUtils();
	}
	
	public String getBasePath() {
		return basePath;
	}
	
	public String getHtmlFolder() {
		return htmlFolder;
	}
	
	public String getHtmlFolderPath() {
		return basePath + File.separator + htmlFolder;
	}
	
	public String getInRecordFolder() {
		return inRecordFolder;
	}
	
	public String getInRecordFolderPath() {
		return basePath + File.separator + htmlFolder + File.separator + inRecordFolder;
	}
	
	public boolean checkFileExists(String folder, String fileName) {
		String file = basePath + File.separator + htmlFolder + File.separator + folder + File.separator + fileName;
		File fi = new File(file);
		return fi.exists();
	}
	
	public void createFolder(String folder) {
		File file = new File(folder);
		file.mkdirs();
		logger.info("nsy-wape::file needed to be created: " + folder);
	}
}
